package com.lbd.system.service.impl;

import com.lbd.bankcard.service.BankCardService;
import com.lbd.system.bean.BindCard;
import com.lbd.system.dao.BindCardRepository;
import com.lbd.system.service.BindCardService;
import com.lbd.base.service.BaseServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service
@Transactional
public class BindCardServiceImpl extends BaseServiceImpl<BindCard, BindCardRepository> implements BindCardService {
    private final Logger log = Logger.getLogger(this.getClass());
    @Autowired
    BindCardRepository bindcardRepository;
    @Autowired
    BankCardService bankCardService;

    @Override
    public Specification<BindCard> getSpecification(BindCard bindcard) {
        return null;
    }

    /**
     * 构建查询语句和参数
     *
     * @param bindcard
     * @param parameter
     * @return
     */
    @Override
    public String buildJpql(BindCard bindcard, Map<String, Object> parameter) {
        StringBuilder jpqlBuilder = new StringBuilder("  from  BindCard t   ");
        if (bindcard != null) {
            if (StringUtils.isNotBlank(bindcard.getUserId())) {
                jpqlBuilder.append(" and userId =:userId");
                parameter.put("userId", bindcard.getUserId());
            }
            if (StringUtils.isNotBlank(bindcard.getBankNo())) {
                jpqlBuilder.append(" and bankNo =:bankNo");
                parameter.put("bankNo", bindcard.getBankNo());
            }

        }
        jpqlBuilder.append(" order by createdDate desc ");
        return jpqlBuilder.toString();
    }

    /**
     * 获取绑卡信息
     *
     * @param bankNo 银行卡号
     * @return
     */
    @Override
    public List<BindCard> findByBankNo(String bankNo) {
        List<BindCard> bindCardList = bindcardRepository.findByBankNo(bankNo);
        return bindCardList;
    }

}
